//------------------------------------------------------------------------------
// Fichiers d'ent�te utilises
//------------------------------------------------------------------------------ 
#include "BasicThresholdFinder.hpp" 
#include "Tools/Logger.hpp"

namespace ImageAnalysis
{

	//------------------------------------------------------------------------------
	// 
	//------------------------------------------------------------------------------ 
	BasicThresholdFinder::BasicThresholdFinder():
	ThresholdFinder()
	{
	
	}
	
	//------------------------------------------------------------------------------
	// 
	//------------------------------------------------------------------------------ 
	BasicThresholdFinder::~BasicThresholdFinder()
	{
	
	}
	
	//------------------------------------------------------------------------------
	// 
	//------------------------------------------------------------------------------ 
	unsigned char * BasicThresholdFinder::GetOneThreshold(Region* regionToStudy, Gradiant* gradiantToStudy)
	{
		//Récupération de l'histogramme de la région du gradiant
		Histogram * histogram = gradiantToStudy->GetHistogram(regionToStudy);
		Tools::ILogger::Log("x:%d,y:%d,w:%d,h:%d\n",regionToStudy->X,regionToStudy->Y,regionToStudy->Width,regionToStudy->Height );
		// Calcul du niveau de seuil
		unsigned char * threshold = new unsigned char [1];
		int value = histogram->GetMeanValue() + histogram->GetStandardDeviation();
		threshold[0] = value>0?value:1;
		
		delete histogram;
		return threshold;
	
	}
	
	//------------------------------------------------------------------------------
	// 
	//------------------------------------------------------------------------------
	unsigned char * BasicThresholdFinder::GetTwoThresholds(Region* regionToStudy, Gradiant* gradiantToStudy)
	{
		//Récupération de l'histogramme de la région du gradiant
		Histogram * histogram = gradiantToStudy->GetHistogram(regionToStudy);
	
		// Calcul du niveau des seuils
		unsigned char * threshold = new unsigned char [2];					
		int value1 = histogram->GetMeanValue() - histogram->GetStandardDeviation();
		int value2 = histogram->GetMeanValue() + histogram->GetStandardDeviation();
		threshold[0] = value1>0?value1:1;
		threshold[1] = value2<=255?value2:255;		
		
		delete histogram;

		return threshold;
	}
}

